import dayjs from 'dayjs'

// 时间戳格式化日期
export function formatTimestamp(timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
  if (!timestamp) return ''
  const ts = String(timestamp).length <= 10 ? Number(timestamp) * 1000 : Number(timestamp)
  if (isNaN(ts)) return ''
  return dayjs(ts).format(format)
}

// 计算相对时间
export function getRelativeTime(timestamp) {
  if (!timestamp) return ''
  const ts = String(timestamp).length <= 10 ? timestamp * 1000 : timestamp
  return dayjs(ts).fromNow()
}
